const puppeteer = require('puppeteer')
const getEle = async () => {
  const browser = await puppeteer.launch({
    headless: false,
    defaultViewport: null,
    args: ['--start-maximized'],
    ignoreDefaultArgs: ['--enable-automation']
  })
  const page = await browser.newPage()
  await page.goto('https://www.tmall.com/')

  const input = await page.$('#mq')
  await input.type('手机')
  // 点击搜索按钮搜索
  // const searchBtn = await page.$('#mallSearch > form > fieldset > div > button')
  // searchBtn.click()

  // 回车搜索
  await page.keyboard.press('Enter')

  await page.waitForSelector('#J_ItemList > div:nth-child(1) > div')
  const title = await page.$eval('#J_ItemList > div:nth-child(1) > div > p.productPrice > em', el => el.innerText)
  console.log(title);

  // 获取一组数据
  await page.waitForSelector('#J_ItemList > div')
  const titleList = await page.$$eval('#J_ItemList > div > div > p.productPrice > em', eles => {
    return eles.map(ele => {
      return  ele.innerText
    })
  })
  console.log(titleList);
}
getEle()
